﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.ComponentModel;

namespace wxtools
{
    [ListBindable(false)]
    public class WxListBoxItemCollection : IList, ICollection, IEnumerable
    {
        #region Fields

        private WxListBox _owner;

        #endregion

        public WxListBoxItemCollection(WxListBox owner)
        {
            _owner = owner;
        }

        internal WxListBox Owner
        {
            get { return _owner; }
        }

        public WxListBoxItem this[int index]
        {
            get { return Owner.OldItems[index] as WxListBoxItem; }
            set { Owner.OldItems[index] = value; }
        }

        public int Count
        {
            get { return Owner.OldItems.Count; }
        }

        public bool IsReadOnly
        {
            get { return Owner.OldItems.IsReadOnly; }
        }

        public int Add(WxListBoxItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            return Owner.OldItems.Add(item);
        }

        public void AddRange(WxListBoxItemCollection value)
        {
            foreach (WxListBoxItem item in value)
            {
                Add(item);
            }
        }

        public void AddRange(WxListBoxItem[] items)
        {
            Owner.OldItems.AddRange(items);
        }

        public void Clear()
        {
            Owner.OldItems.Clear();
        }

        public bool Contains(WxListBoxItem item)
        {
            return Owner.OldItems.Contains(item);
        }


        public void CopyTo(WxListBoxItem[] destination, int arrayIndex)
        {
            Owner.OldItems.CopyTo(destination, arrayIndex);
        }

        public int IndexOf(WxListBoxItem item)
        {
            return Owner.OldItems.IndexOf(item);
        }

        public void Insert(int index, WxListBoxItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            Owner.OldItems.Insert(index, item);
        }

        public void Remove(WxListBoxItem item)
        {
            Owner.OldItems.Remove(item);
        }

        public void RemoveAt(int index)
        {
            Owner.OldItems.RemoveAt(index);
        }

        public IEnumerator GetEnumerator()
        {
            return Owner.OldItems.GetEnumerator();
        }



        int IList.Add(object value)
        {
            if (!(value is WxListBoxItem))
            {
                throw new ArgumentException();
            }
            return Add(value as WxListBoxItem);
        }

        void IList.Clear()
        {
            Clear();
        }

        bool IList.Contains(object value)
        {
            return Contains(value as WxListBoxItem);
        }

        int IList.IndexOf(object value)
        {
            return IndexOf(value as WxListBoxItem);
        }

        void IList.Insert(int index, object value)
        {
            if (!(value is WxListBoxItem))
            {
                throw new ArgumentException();
            }
            Insert(index, value as WxListBoxItem);
        }

        bool IList.IsFixedSize
        {
            get { return false; }
        }

        bool IList.IsReadOnly
        {
            get { return IsReadOnly; }
        }

        void IList.Remove(object value)
        {
            Remove(value as WxListBoxItem);
        }

        void IList.RemoveAt(int index)
        {
            RemoveAt(index);
        }

        object IList.this[int index]
        {
            get
            {
                return this[index];
            }
            set
            {
                if (!(value is WxListBoxItem))
                {
                    throw new ArgumentException();
                }
                this[index] = value as WxListBoxItem;
            }
        }



        void ICollection.CopyTo(Array array, int index)
        {
            CopyTo((WxListBoxItem[])array, index);
        }

        int ICollection.Count
        {
            get { return Count; }
        }

        bool ICollection.IsSynchronized
        {
            get { return false; }
        }

        object ICollection.SyncRoot
        {
            get { return this; }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

}
